package com.hxgis.common.utils;


import com.hxgis.common.utils.quickhull.QuickHull;
import com.hxgis.common.utils.quickhull.datastructures.LinkedList;
import com.hxgis.common.utils.quickhull.datastructures.LinkedListNode;
import org.geojson.Feature;
import org.geojson.FeatureCollection;
import org.geojson.LngLatAlt;
import org.geojson.Polygon;

import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GeoUtil {



    public static FeatureCollection draw(LinkedList calcPointsSet,String type){

        FeatureCollection featureCollection = new FeatureCollection();

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("valueType", type);
//            properties.put("color", type.equals("P") ? "blue" : "red");

        Feature feature = new Feature();
        Polygon polygon = new Polygon();
        List<LngLatAlt> list = new ArrayList<>();
        List<Point2D> point2DS = new ArrayList<>();
//        List<Point2D> smList = new ArrayList<>();

        LinkedListNode node = calcPointsSet.getHead();
        while (node != null) {
            Point2D.Double point = node.getPoint();
            point2DS.add(point);
            node = node.getNext();
        }

        //平滑输出多边形
//        smList = Smooth.smooth(point2DS);
//        smList = Smooth.smooth(smList);
//        smList = Smooth.smooth(smList);

        for (int i = 0; i < point2DS.size(); i++) {
            list.add(new LngLatAlt(point2DS.get(i).getX(), point2DS.get(i).getY()));
        }

        polygon.add(list);
        feature.setGeometry(polygon);
        feature.setProperties(properties);
        featureCollection.add(feature);
        return  featureCollection;
    }







}
